<template>
  <v-box :title="'操作日志'">
    <view class="cbox" style=" height: 100%;">
      <v-center style="height: 100%">
        <template #head>
          <v-center
            style="
              min-height: 70px;
              height: auto;
              background: #f3f3f3;
              padding: 0 15px;
            "
            class="form_search"
            :row="true"
          >
            <template #head>
              <n-form-item label="操作人员" label-placement="left"  style="min-width:50px;">
                <n-input v-model:value="searchData.uname" placeholder="请输入操作人员姓名" clearable/>
              </n-form-item>
              <view style="width: 15px"></view>   

              <n-form-item label="操作时间" label-placement="left"  style="width:500px;">
                <n-config-provider :locale="zhCN" :date-locale="dateZhCN">
                  <n-date-picker v-model:value="searchData.startDate" type="daterange" clearable />
                </n-config-provider>
              </n-form-item>
              <view style="width: 15px"></view>      
            </template>
            <template #end>
              <n-button  @click="searchInput" ghost color="#2f9385" style="width:160px;margin-right: 15px">
                <template #icon>
                  <icon :icon="['fal', 'search']"></icon>
                </template>
                搜索
              </n-button>
            </template>
          </v-center>
        </template>
        <template #center>
          <v-center style="height: 100%; padding-top: 15px">
            <template #center>
              <table-show
                :tableData="table_data"
                :columns="columns"
                :pageNum="pageNum"
                :pageSize="pageSize"
                :totalPages="totalPages"
                :loading="loading"
                @getCPage="getCPage"
                @getPageSize="getPageSize"
              />
            </template>
          </v-center>
        </template>
      </v-center>
    </view>
  </v-box>
</template>
<script>
import VBox from "@/components/scraw/VBox.vue";
import VCenter from "@/components/scraw/VCenter.vue";
import TableShow from "@/components/form/TableShow.vue";
import {zhCN, dateZhCN} from "naive-ui"
export default {
  components: {
    VBox,
    VCenter,
    TableShow
  },
  props:['type'],
  data() {
    return {
      search: "",
      table_data: [],
      pageNum: 1,
      pageSize: 10,
      totalPages: 0,
      loading: true,
      searchData:{
        uname: null,
        startDate:null, 
      },
      showModal: false,
      BUName:null,
    };
  },
  methods: {    
    searchInput() {
      this.getDevice()
    },
    getCPage(pageNum) {
      this.pageNum = pageNum;
      this.getDevice()
    },
    getPageSize(pagesize) {
      this.pageSize = pagesize;
      this.getDevice()
    }
  },
  mounted() {
    this.getDevice();
  },
  setup() {
    var columns =  [
      { title: "操作内容", key: "UContent" },
      { title: "操作时间", key: "UTime", width:200 },
      { title: "操作人员", key: "UName", width:200 },
    ]
    var getDevice = function (succes) {
      /** 禁用 http 模式的默认加载提醒 */
      // this.$default_hloading.isload = false
      this.loading = true
      this.$http
        .get("getAlllogger", {
          params: {
            pageSize: this.pageSize,
            pageNum: this.pageNum,
            type:  this.type,

            uname: this.searchData.uname,
            startDate: !this.searchData.startDate ? null:this.searchData.startDate[0],
            endDate: !this.searchData.startDate ? null:(this.searchData.startDate[1] + ( 24*60*60 - 1)* 1000),
          },
        })
        .then((res) => {
          this.table_data = res.data.msg.data;
          this.totalPages = res.data.msg.size;
          if(succes) succes(this)
        }).catch(()=>{
          this.table_data = [];
        }).finally(()=>{
          this.loading = false
        });
    }
    return {
      zhCN, dateZhCN, columns, getDevice, 
    }
  },
};
</script>